using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;

using FredCK.FCKeditorV2;
using System.Runtime.CompilerServices;
using System.Collections;
using System.Web.UI;
using System.Web;
using System.IO;
using System.Threading;
using Microsoft.VisualBasic.CompilerServices;
using Microsoft.VisualBasic;


namespace Adge.Web
{
    public class FckHtmlEditorProvider : HtmlEditorProvider
    {
        // Fields
        private ArrayList _AdditionalToolbars = new ArrayList();
        private string _availableToolbarSets;
        private string _availableToolbarSkins;
        [AccessedThroughProperty("cntlFck")]
        private FCKeditor _cntlFck;
        private string _ControlID;
        private string _CSSDefaultMode;
        private string _CustomConfigurationPath;
        private string _customOptionsDialog;
        private string _defaultFlashGallerySkin;
        private string _defaultImageGallerySkin;
        private string _defaultLinksGallerySkin;
        private string _defaultToolbarSet;
        private string _defaultToolbarSkin;
        private string _DynamicCSSGeneratorPath;
        private string _DynamicStylesGeneratorPath;
        private bool _EnhancedSecurityDefault;
        private bool _FCKDebugMode;
        private string _FlashGalleryPath;
        private string _FlashUploadPath;
        private Unit _ForceHeight;
        private Unit _ForceWidth;
        private string _ImageFileFilter;
        private string _ImageGalleryPath;
        private string _ImageUploadPath;
        private string _LinksGalleryPath;
        private string _optionsOpenMode;
        private string _providerPath = "~/";
        private string _RootImageDirectory = "~/images";
        private string _SecureConfigurationPath;
        private string _spellCheck;
        private string _StaticCSSFile;
        private string _StaticStylesFile;
        private ArrayList _styles;
        private string _StylesDefaultMode;
        private bool _UseFCKSource;
        private const string ProviderType = "htmlEditor";

        // Methods
        public FckHtmlEditorProvider()
        {

        }

        public override void AddToolbar()
        {
        }

        public override void Initialize()
        {

            this.cntlFck = new FCKeditor();
            this.cntlFck.ID = this.ControlID;
            string providerPath = this.ProviderPath;

            this.cntlFck.BasePath = providerPath + "FCKeditor/";
            this.cntlFck.ToolbarSet = this._defaultToolbarSet;
            //this.cntlFck.SkinPath = base.ResolveClientUrl(providerPath + "FCKeditor/editor/skins/" + this._defaultToolbarSkin + "/");
            //this.cntlFck.AutoDetectLanguage = false;
            //string path = HttpContext.Current.Server.MapPath(providerPath + "FCKeditor/editor/lang/" + Thread.CurrentThread.CurrentUICulture.Name + ".js");
            //if (File.Exists(path))
            //{
            //    this.cntlFck.DefaultLanguage = Path.GetFileNameWithoutExtension(path);
            //}
            //else
            //{
            //    this.cntlFck.DefaultLanguage = Strings.Left(Thread.CurrentThread.CurrentUICulture.Name, 2);
            //}            
            this.cntlFck.FullPage = false;
            this.cntlFck.ToolbarCanCollapse = true;


        }

        // Properties
        public override ArrayList AdditionalToolbars
        {
            get
            {
                return this._AdditionalToolbars;
            }
            set
            {
                this._AdditionalToolbars = value;
            }
        }

        public string AvailableToolbarSets
        {
            get
            {
                return this._availableToolbarSets;
            }
        }

        private FCKeditor cntlFck
        {
            get
            {
                return this._cntlFck;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._cntlFck != null)
                {
                }
                this._cntlFck = value;
                if (this._cntlFck != null)
                {
                }
            }
        }

        public override string ControlID
        {
            get
            {
                return this._ControlID;
            }
            set
            {
                this._ControlID = value;
            }
        }

        public string CSSDefaultMode
        {
            get
            {
                return this._CSSDefaultMode;
            }
        }       

        public string CustomOptionsDialog
        {
            get
            {
                return this._customOptionsDialog;
            }
        }

        public string DefaultFlashGallerySkin
        {
            get
            {
                return this._defaultFlashGallerySkin;
            }
        }

        public string DefaultImageGallerySkin
        {
            get
            {
                return this._defaultImageGallerySkin;
            }
        }

        public string DefaultLinksGallerySkin
        {
            get
            {
                return this._defaultLinksGallerySkin;
            }
        }

        public string DefaultToolbarSet
        {
            get
            {
                return this._defaultToolbarSet;
            }
        }         

        
        public bool EnhancedSecurityDefault
        {
            get
            {
                return this._EnhancedSecurityDefault;
            }
        }

       
        public Unit ForceHeight
        {
            get
            {
                return this._ForceHeight;
            }
            set
            {
                this._ForceHeight = value;
            }
        }

        public Unit ForceWidth
        {
            get
            {
                return this._ForceWidth;
            }
            set
            {
                this._ForceWidth = value;
            }
        }

        public override Unit Height
        {
            get
            {
                return this.cntlFck.Height;
            }
            set
            {
                Unit unit;
                if (!this._ForceHeight.IsEmpty)
                {
                    unit = this._ForceHeight;
                }
                else
                {
                    unit = value;
                }
                this.cntlFck.Height = unit;
            }
        }

        public override Control HtmlEditorControl
        {
            get
            {
                return this.cntlFck;
            }
        }

        public string ImageFileFilter
        {
            get
            {
                return this._ImageFileFilter;
            }
        }
      

        public bool IsFCKDebug
        {
            get
            {
                return this._FCKDebugMode;
            }
        }


        public string OptionsOpenMode
        {
            get
            {
                return this._optionsOpenMode;
            }
        }

        public string ProviderPath
        {
            get
            {
                return this._providerPath;
            }
        }

        public override string RootImageDirectory
        {
            get
            {                
                return this._RootImageDirectory;
            }
            set
            {
                this._RootImageDirectory = value;
            }
        }


        public string StylesDefaultMode
        {
            get
            {
                return this._StylesDefaultMode;
            }
        }

        public override string Text
        {
            get
            {
                string text2;                
                try
                {                    
                    text2 = this.cntlFck.Value;
                }
                catch (Exception exception1)
                {
                    ProjectData.SetProjectError(exception1);
                    Exception exception = exception1;
                    text2 = this.cntlFck.Value;
                    //ProjectData.ClearProjectError();
                }
                return text2;
            }
            set
            {
                this.cntlFck.Value = value;
            }
        }

        public override Unit Width
        {
            get
            {
                return this.cntlFck.Width;
            }
            set
            {
                Unit unit;
                if (!this._ForceWidth.IsEmpty)
                {
                    unit = this._ForceWidth;
                }
                else
                {
                    unit = value;
                }
                this.cntlFck.Width = unit;
            }
        }
    }

}
